#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int n, q, a[300005];
ll s1[300005], s2[300005], s3[300005];

int main()
{
    cin >> n >> q;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        s1[i] = s1[i-1] + a[i];
        s2[i] = s2[i-1] + 1LL * a[i] * i;
        s3[i] = s3[i-1] + 1LL * a[i] * i * i;
    }
    
    while(q--)
    {
        int l, r;
        cin >> l >> r;
        ll x = s1[r] - s1[l-1];
        ll y = s2[r] - s2[l-1];
        ll z = s3[r] - s3[l-1];
        cout << (l + r) * y - z + (r - l + 1 - 1LL * l * r) * x << "\n";
    }
    
    return 0;
}